_Pragma("once")

#include <chrono>
#include <string>

namespace sdl_engine::component::benchmark {

class Benchmark final {
public:
    Benchmark(const std::string& msg): msg_(msg) {
        start_ = std::chrono::high_resolution_clock::now();
    }

    ~Benchmark() {
        auto endTime = std::chrono::high_resolution_clock::now();

        auto start = std::chrono::time_point_cast<std::chrono::microseconds>(start_).time_since_epoch().count();
        auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTime).time_since_epoch().count();
        auto duration = end - start;

        double ms = duration * 0.001;
        printf(
               "[Benchmark] %s: %lfms\n",
               msg_.c_str(), ms
              );
    }

private:
    std::chrono::time_point<std::chrono::high_resolution_clock> start_;
    std::string msg_;
};

}
